package com.lwj.charts.commonutils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lwj.charts.pojo.Bar;
import com.lwj.charts.pojo.Line;
import com.lwj.charts.pojo.Pie;
import com.lwj.charts.service.BarService;
import com.lwj.charts.service.LineService;
import com.lwj.charts.service.PieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

@Service
public class SendMessageSercice {
    @Autowired
    BarService barService;
    @Autowired
    LineService lineService;
    @Autowired
    PieService pieService;

    public void sendDataToWeb() throws SQLException {
//        Bar图
        QueryWrapper<Bar> barwrapper = new QueryWrapper<>();
        barwrapper.last("limit 7");
        List<Bar> LeftBar = barService.list(barwrapper);
        barwrapper.last("limit 7,5");
        List<Bar> RightBar = barService.list(barwrapper);
//        line图
        QueryWrapper<Line> linewrapper = new QueryWrapper<>();
        linewrapper.last("limit 30,12");
        List<Line> RightLine = lineService.list(linewrapper);
        linewrapper.last("limit 30");
        List<Line> LeftLine = lineService.list(linewrapper);
//        pie图
        QueryWrapper<Pie> piewrapper = new QueryWrapper<>();
        piewrapper.last("limit 5");
        List<Pie> LeftPie = pieService.list(piewrapper);
        piewrapper.last("limit 5,8");
        List<Pie> RightPie = pieService.list(piewrapper);
        WebSocketServer.sendData(null,
                Result.ok().data("LeftBar", LeftBar)
                        .data("RightBar", RightBar)
                        .data("LeftLine",LeftLine)
                        .data("RightLine",RightLine)
                        .data("LeftPie",LeftPie)
                        .data("RightPie",RightPie));
    }
    public void sendDataToWebTime() throws SQLException {
//        Bar图
        QueryWrapper<Bar> barwrapper = new QueryWrapper<>();
        barwrapper.last("limit 12,7");
        List<Bar> LeftBar = barService.list(barwrapper);
        barwrapper.last("limit 19,5");
        List<Bar> RightBar = barService.list(barwrapper);
//        line图
        QueryWrapper<Line> linewrapper = new QueryWrapper<>();
        linewrapper.last("limit 77,12");
        List<Line> RightLine = lineService.list(linewrapper);
        linewrapper.last("limit 47,30");
        List<Line> LeftLine = lineService.list(linewrapper);
//        pie图
        QueryWrapper<Pie> piewrapper = new QueryWrapper<>();
        piewrapper.last("limit 13,5");
        List<Pie> LeftPie = pieService.list(piewrapper);
        piewrapper.last("limit 18,8");
        List<Pie> RightPie = pieService.list(piewrapper);
        WebSocketServer.sendData(null,
                Result.ok().data("LeftBar", LeftBar)
                        .data("RightBar", RightBar)
                        .data("LeftLine",LeftLine)
                        .data("RightLine",RightLine)
                        .data("LeftPie",LeftPie)
                        .data("RightPie",RightPie));
    }
}

